import request from '@/utils/request'

export function login(data) {
    return request({
        url: '/user/token',
        method: 'POST',
        data
    })
}

export function register(data) {
    return request({
        url: '/user/accounts',
        method: 'POST',
        data
    })
}

export function getInfo(token) {
    return request({
        url: '/user/info',
        method: 'GET',
        params: { token }
    })
}

// 忘记密码流程
export function getQuestionByUid(id) {
    return request({
        url: '/user/' + id + '/question',
        method: 'GET'
    }).then(data => data.question)
}
export function getTokenByAnswer(params) {
    return request({
        url: '/user/reset_token',
        method: 'GET',
        params
    }).then(data => data.token)
}
export function resetPassword(data) {
    return request({
        url: '/user/password_reset',
        method: 'PATCH',
        data
    })
}

// 获取系统内整体用户列表
export function getUserList(params) {
    return request({
        url: '/user/condition',
        method: 'GET',
        params
    }).then(data => data.page_res)
}

// 获取待审核编辑者接口
export function getAuditList() {
    return request({
        url: '/user/wait',
        method: 'GET'
    }).then(data => data.userlist)
}

// 删除用户接口
export function deleteUser(id) {
    return request({
        url: '/user/' + id,
        method: 'DELETE'
    })
}

// 管理员直接创建用户
export function createUser(data) {
    return request({
        url: '/user/add_user',
        method: 'POST',
        data
    }).then(data => data.user)
}

// 管理员修改完整用户
export function adminUpdateUser(data) {
    return request({
        url: '/user/accountOnAdmin',
        method: 'PUT',
        data
    }).then(data => data.user)
}

// 用户修改个人密码
export function updatePassword(data) {
    return request({
        url: '/user/password',
        method: 'PUT',
        data
    })
}

// 用户修改自身信息
export function updateUser(data) {
    return request({
        url: '/user/account',
        method: 'PUT',
        data
    }).then(data => data.user)
}

// 审核用户通过
export function admitUserById(id) {
    return request({
        url: '/user/permission',
        method: 'POST',
        data: {
            userid: id
        }
    })
}

// 拒绝用户审核
export function rejectUserById(id) {
    return deleteUser(id)
}

// 批量新增用户
export function batchCreateUsers(data) {
    return request({
        url: '/user/batch',
        method: 'POST',
        data
    }).then(data => data.ack_list)
}

// 获取教师信息
export function getTeacherInfo(id) {
    return request({
        url: '/teacher/' + id,
        method: 'GET'
    }).then(data => data.teacherInfo)
}

// 更新教师信息
export function updateTeacherInfo(data) {
    return request({
        url: '/teacher/' + data.id,
        method: 'PUT',
        data
    })
}
